<template>
  <el-date-picker
    v-model="timeRange"
    type="datetimerange"
    :picker-options="pickerOptions"
    class="my-datetime-picker"
    range-separator="至"
    start-placeholder="开始日期"
    end-placeholder="结束日期"
    :clearable="false"
    size="mini"
    align="right"
  >
  </el-date-picker>

</template>

<script>
export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近5分钟',
          onClick(picker) {
            const end = new Date().getTime()
            const start = new Date().getTime() - 300 * 1000
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近10分钟',
          onClick(picker) {
            const end = new Date().getTime()
            const start = new Date().getTime() - 600 * 1000
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近30分钟',
          onClick(picker) {
            const end = new Date().getTime()
            const start = new Date().getTime() - 1800 * 1000
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近1小时',
          onClick(picker) {
            const end = new Date().getTime()
            const start = new Date().getTime() - 3600 * 1000
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近3小时',
          onClick(picker) {
            const end = new Date().getTime()
            const start = new Date().getTime() - 3600 * 1000 * 3
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近12小时',
          onClick(picker) {
            const end = new Date().getTime()
            const start = new Date().getTime() - 3600 * 1000 * 12
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近1天',
          onClick(picker) {
            const end = new Date().getTime()
            const start = new Date().getTime() - 3600 * 1000 * 24
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近3天',
          onClick(picker) {
            const end = new Date().getTime()
            const start = new Date().getTime() - 3600 * 1000 * 24 * 3
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近7天',
          onClick(picker) {
            const end = new Date().getTime()
            const start = new Date().getTime() - 3600 * 1000 * 24 * 7
            picker.$emit('pick', [start, end])
          }
        }]
      },
      timeRange: [new Date().getTime() - 1800 * 1000, new Date().getTime()]
    }
  },
  computed: {

  },
  watch: {
    timeRange() {
      this.$emit('child-time', this.timeRange)
    }
  },
  mounted() {

  },
  methods: {

  }

}
</script>

<style>
/* elem时间组件 */
.my-datetime-picker.el-input__inner {
  border-radius: 4px;
  color: #464c5b;
}

.my-datetime-picker .el-range-separator {
  padding: 0;
  width: auto;
}

.my-datetime-picker .el-range__icon {
  /*color: #2d8cf0;*/
  /*font-weight: 700;*/
}

.my-datetime-picker .el-range-input {
  font-weight: 400;
  width: auto;
}

.my-datetime-picker.el-date-editor--datetimerange.el-input,
.my-datetime-picker.el-date-editor--datetimerange.el-input__inner {
  width: 290px;
}

.my-datetime-picker .el-range-editor.el-input__inner {
  padding: 3px 0;
}
</style>
